import { lazyBatchReport } from '../report/index'

/**
 * 页面load统计时间
 */
export default function observerLoad() {
  window.addEventListener(
    'pageshow',
    (event) => {
      requestAnimationFrame(() => {
        ;['load'].forEach((eventName) => {
          const reportData = {
            type: 'performance',
            subType: eventName,
            pageUrl: window.location.href,
            startTime: performance.now() - event.timeStamp,
          }

          // 数据上报
          lazyBatchReport(reportData)
        })
      })
    },
    true,
  )
}
